<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">

<head>
    <meta charset="UTF-8">
    <title>表单页面</title>
    <link rel="stylesheet" href="/static/component/pear/css/pear.css" />
</head>

<body>
    <form class="layui-form" id="formId">
        <div class="mainBox">
            <div class="main-container">
                <div class="layui-form-item">
                    <label class="layui-form-label">父级节点</label>
                    <div class="layui-input-block">
                        <input type="text"  value="{$msg.ptitle}" disabled  autocomplete="off" class="layui-input">
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">权限名称</label>
                    <div class="layui-input-block">
                        <input type="text" name="title" lay-verify="title" value="{$msg.title|default=''}" autocomplete="off" placeholder="请输入权限名称"
                            class="layui-input">
                    </div>
                </div>
                {if $Request.get.pid}
                <div class="layui-form-item">
                    <label class="layui-form-label">跳转类型</label>
                    <div class="layui-input-block">
                        <input type="text" name="openType" value="{$msg.openType|default='_iframe'}" lay-verify="openType" autocomplete="off"
                            placeholder="请输入跳转类型" class="layui-input">
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">URL</label>
                    <div class="layui-input-block">
                        <input type="text" name="url" value="{$msg.url|default=''}" autocomplete="off"
                            placeholder="请输入URL" class="layui-input">
                    </div>
                </div>
                {/if}
                {if !$Request.get.pid || $Request.get.pid==0}
                <div class="layui-form-item">
                    <label class="layui-form-label">图标</label>
                    <div class="layui-input-block">
                        <input type="text" name="icon" value="{$msg.icon|default='layui-icon-template-1'}" id="iconPicker" lay-verify="iconPicker" autocomplete="off" class="layui-input">
                    </div>
                </div>
                {/if}
                {if !$Request.get.pid}

                  <input type="hidden" name="type" value="0">
                {else/} 
                    <input type="hidden" name="type" value="1">
                {/if}
                <div class="layui-form-item">
                    <label class="layui-form-label">状态</label>
                    <div class="layui-input-block">
                        {php} 
                            $status=[
                                0=> empty($msg['status']) ? "checked" : "",
                                1=> empty($msg['status']) ? "" : "checked",
                            ];
                        {/php}
                        <input type="radio" name="status" value="0" title="关闭" {$status[0]}>
                        <input type="radio" name="status" value="1" title="开启" {$status[1]}>
                    </div>
                </div>
            </div>
        </div>
        <div class="bottom">
            <div class="button-container">
                <button type="submit" class="pear-btn pear-btn-primary pear-btn-sm" lay-submit=""
                    lay-filter="form-save">
                    <i class="layui-icon layui-icon-ok"></i>
                    提交
                </button>
                <button type="reset" class="pear-btn pear-btn-sm">
                    <i class="layui-icon layui-icon-refresh"></i>
                    重置
                </button>
            </div>
        </div>
    </form>
    <script src="/static/user/js/jquery.min.js"></script>
    <script src="/static/component/layui/layui.js"></script>
    <script src="/static/component/pear/pear.js"></script>
    <script>
        layui.use(['form', 'jquery', 'iconPicker'], function () {
            let form = layui.form;
            let $ = layui.jquery;

            var iconPicker = layui.iconPicker;
            iconPicker.render({
                elem: '#iconPicker',
                type: 'fontClass',
                search: true,
                page: true,
                limit: 16,
                click: function (data) {
                    console.log(data);
                },
                success: function (d) {
                    console.log(d);
                }
            });


            form.on('submit(form-save)', function (data) {
                var data = $("#formId");
                postDatai("{:url('admin/opItemSave')}?id={$Request.get.id}&pid={$Request.get.pid}", data).then(function (res) {
                    if (res.code == 200) {
                        layer.msg(res.message, {
                            icon: 1,
                            time: 1000
                        }, function () {
                            parent.layer.close(parent.layer.getFrameIndex(window
                                .name)); //关闭当前页
                            parent.layui.treetable.reload("#tableId");
                        });
                    } else {
                        layer.msg(res.message, {
                            icon: 2,
                            time: 1000
                        });
                    }
                });
                return false;
            });
        })
    </script>
    {include file="base/unitjs"}
</body>

</html>